package com.yuandian.management.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfExclusiveIndicator;
import com.yuandian.api.management.validate.InsertFlag;
import com.yuandian.api.management.validate.UpdateFlag;
import com.yuandian.bpm.admin.api.feign.RemoteParamService;
import com.yuandian.bpm.common.core.constant.SecurityConstants;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.constant.ConfigKey;
import com.yuandian.constant.Constants;
import com.yuandian.management.service.ConfExclusiveIndicatorService;
import com.yuandian.management.service.ExclusiveIndicatorService;
import com.yuandian.management.utils.DisplayFieldUtil;
import com.yuandian.management.vo.ExclusiveIndicatorVo;
import com.yuandian.management.vo.IndicatorsSyncParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.*;

/**
 * 专属指标表-Controller
 * @author zfsn
 * @date 2023-3-22
 */
@Api(tags = "专属指标管理-专属指标")
@RestController
@RequestMapping("/exclusiveIndicator")
public class ConfExclusiveIndicatorController {

	private static final Logger LOG = LoggerFactory.getLogger(ConfExclusiveIndicatorController.class);

	@Autowired
	private ConfExclusiveIndicatorService confExclusiveIndicatorService;

	@Autowired
	private ExclusiveIndicatorService exclusiveIndicatorService;

	@Autowired
	private RemoteParamService remoteParamService;

	/**
	 * 通过主键查询数据
	 * @param resourceCode 业务资源
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过业务资源查询数据", notes = "通过业务资源查询数据")
	@GetMapping("/{resourceCode}")
	public R<ConfExclusiveIndicator> queryByResourceCode(@PathVariable("resourceCode") String resourceCode) {
		return R.ok(confExclusiveIndicatorService.getExclusiveIndicatorByResourceCode(resourceCode));
	}


	/**
	 * 分页查询
	 * @param confExclusiveIndicator 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "businessCode", value = "所属业务编码", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "stepCode", value = "步骤编码", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "segmentTypeId", value = "端类型", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "segmentId", value = "网端id", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "parentResourceCode", value = "父服务资源编码", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "resourceCode", value = "资源编码", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "name", value = "标识名称", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "identifyStr", value = "业务服务资源匹配串", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "isShow", value = "是否显示: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isDeal", value = "是否交易标示: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isUserFlag", value = "是否是用户标识: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isChannel", value = "渠道标识: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isRegion", value = "区域标识: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isAsc", value = "排序的方向值只能是 desc 或者 asc", paramType = "body", required = true, dataType = "String"),
	})
	public R<Page<ExclusiveIndicatorVo>> listPage(@RequestBody ConfExclusiveIndicator confExclusiveIndicator) {
		return R.ok(confExclusiveIndicatorService.listPage(confExclusiveIndicator));
	}

	/**
	 * 新增数据
	 * @param confExclusiveIndicator 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增专属指标表数据")
	@PostMapping("/save")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCode", 		value = "资源编码", 						paramType = "body", required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "name", 				value = "标识名称",  					paramType = "body", required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "identifyStr", 		value = "业务服务资源匹配串", 				paramType = "body", required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "source", 				value = "来源",  		 				paramType = "body", required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "keyword",  			value = "关键字",  		 				paramType = "body", required = false, 	dataType = "String"),
			@ApiImplicitParam(name = "keywordType",  		value = "值类型",  		 				paramType = "body", required = false, 	dataType = "String"),
			@ApiImplicitParam(name = "matchRegular",  		value = "匹配符",  		 				paramType = "body", required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "formatStr",  			value = "格式化串",  					paramType = "body", required = false, 	dataType = "String"),
			@ApiImplicitParam(name = "isShow", 				value = "是否显示: 0否, 1是", 			paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isDeal",  			value = "是否交易标示: 0否, 1是",  		paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isUserFlag",  		value = "是否交易标示: 0否, 1是",  		paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isChannel",  			value = "渠道标识: 0否, 1是", 			paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isRegion",  			value = "区域标识: 0否, 1是", 			paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isCustomReqCode", 	value = "是否是自定义返回码 0否, 1是", 		paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isBusinessHallCode",  value = "是否是营业厅标识 0否, 1是", 		paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isOperatorCode", 		value = "是否是工号 0否, 1是", 			paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isPhoneNumber", 		value = "是否是手机号 0否, 1是 ",  		paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isAlarm",  			value = "是否是告警提示 0否, 1是", 		paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isBackFill",  		value = "需要通过用户关联信息回填 0否, 1是", paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "relevanceType",  		value = "关联指标  0 非关联指标、 1. 是前端关联指标、2.是后端关联指标、 3. 是前后端关联指标", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isShowSensitive", 	value = "展示是否脱敏 0否, 1是", 			paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "decodeType",  		value = "解码方式, 0.否 1.Base64解码 2.Unicode解码 3.url解码 4.url+unicode解码", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isRetainOri",  		value = "是否保留原始数据 0否, 1是 ", 		paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isFullExtraction", 	value = "是否全量提取 0否, 1是", 			paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isExportSensitive", 	value = "导出脱敏 0否, 1是", 				paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "sensitiveStartValue", value = "脱敏开始数值",  					paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "sensitiveLength", 	value = "脱敏长度", 						paramType = "body", required = false, 	dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isSensitiveInformation", 	value = "是否是敏感信息 0否, 1是", 						paramType = "body", required = false, 	dataTypeClass = Integer.class),
	})
	public R<Boolean> save(@Validated(InsertFlag.class) @RequestBody @ApiIgnore ConfExclusiveIndicator confExclusiveIndicator) {
		return R.ok(confExclusiveIndicatorService.save(confExclusiveIndicator));
	}

	/**
	 * 通过id更新数据
	 * @param confExclusiveIndicator 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过id更新数据", notes = "通过id更新数据")
	@PutMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "resourceCode", value = "资源编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "name", value = "标识名称", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "identifyStr", value = "业务服务资源匹配串", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "source", value = "来源", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "keyword", value = "关键字", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "keywordType", value = "值类型", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "matchRegular", value = "匹配符", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "formatStr", value = "格式化串", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "isShow", value = "是否显示: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isDeal", value = "是否交易标示: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isUserFlag", value = "是否交易标示: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isChannel", value = "渠道标识: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isRegion", value = "区域标识: 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isCustomReqCode", value = "是否是自定义返回码 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isBusinessHallCode", value = "是否是营业厅标识 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isOperatorCode", value = "是否是工号 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isPhoneNumber", value = "是否是手机号 0否, 1是 ", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isAlarm", value = "是否是告警提示 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isBackFill", value = "需要通过用户关联信息回填 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "relevanceType", value = "关联指标  0 非关联指标、 1. 是前端关联指标、2.是后端关联指标、 3. 是前后端关联指标", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isShowSensitive", value = "展示是否脱敏 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "decodeType", value = "解码方式, 0.否 1.Base64解码 2.Unicode解码 3.url解码 4.url+unicode解码", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isRetainOri", value = "是否保留原始数据 0否, 1是 ", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isFullExtraction", value = "是否全量提取 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isExportSensitive", value = "导出脱敏 0否, 1是", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "sensitiveStartValue", value = "脱敏开始数值", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "sensitiveLength", value = "脱敏长度", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isSensitiveInformation", 	value = "是否是敏感信息 0否, 1是", 						paramType = "body", required = false, 	dataTypeClass = Integer.class),
	})
	public R<String> updateByResourceCode(@RequestBody @ApiIgnore @Validated(UpdateFlag.class) ConfExclusiveIndicator confExclusiveIndicator) {
		return confExclusiveIndicatorService.updateByResourceCode(confExclusiveIndicator);
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@DeleteMapping("/delete/{ids}")
	public R<Boolean> removeByIds(@PathVariable("ids") List<Integer> ids){
		confExclusiveIndicatorService.removeByIds(ids);
		return R.ok();
	}


	/**
	 * 下载专属指标导入模板
	 * @param response 响应上下文
	 */
	@ApiOperation(value = "下载专属指标导入模板", notes = "下载专属指标导入模板")
	@GetMapping("/importTemplate")
	public void importTemplate(HttpServletResponse response) {
		try {
			confExclusiveIndicatorService.importTemplate(response);
		} catch (Exception e) {
			LOG.error(e.getMessage(), e);
		}
	}

	/**
	 * 导出(下载)专属指标列表
	 * @param exclusiveIndicator 专属指标查询参数
	 */
	@PostMapping("/download")
	@ApiOperation(value = "导出(下载)专属指标列表", notes = "导出(下载)专属指标列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCodes", value = "资源编码(支持多选)", paramType = "body", required = true, dataType = "String"),
	})
	public void download(@RequestBody @ApiIgnore ConfExclusiveIndicator exclusiveIndicator, HttpServletResponse response) {
		try {
			confExclusiveIndicatorService.downloadExclusiveIndicators(exclusiveIndicator, response);
		} catch (Exception e1) {
			LOG.error(e1.getMessage(), e1);
			response.reset();
			response.setContentType(Constants.CONTENT_TYPE_APPLICATION_JSON);
			response.setCharacterEncoding("utf-8");
			try {
				response.getWriter().println(JSONUtil.parse(R.failed("导出Excel文件失败！")));
			} catch (IOException e2) {
				LOG.error(e2.getMessage(), e2);
			}
		}
	}




	/**
	 * 组装需要展示的字段(需求886-20220510)
	 * @param map 有序的 LinkedHashMap
	 * @return
	 */
	@ApiIgnore
	@PostMapping("/assemblyDisplayField")
	@ApiOperation(value = "组装需要展示的字段", notes = "组装需要展示的字段")
	public Map<String, Object> assemblyDisplayField(@RequestBody Map<String, Object> map) {
		return confExclusiveIndicatorService.assemblyDisplayField(map);
	}


	/**
	 * 动态获取需要展示的所有字段（需求886）
	 *
	 * @return Result
	 */
	@GetMapping("/getAllCustomDisplayFields/{type}")
	public R<Map<String, Object>> getAllCustomDisplayFields(@NotNull @PathVariable String type) {
		return R.ok(confExclusiveIndicatorService.queryCustomDisplayFields(type));
	}

	/**
	 * 根据业务资源获取系统,业务名称，步骤名称信息
	 * @param
	 * @return
	 */
	@PostMapping("/systemInfo")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCode", value = "资源编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isAsc", value = "排序的方向值只能是 desc 或者 asc", paramType = "body", required = true, dataType = "String"),

	})
	@ApiOperation(value = "根据业务资源获取系统,业务名称，步骤名称信息", notes = "根据业务资源获取系统,业务名称，步骤名称信息")
	public R<Page<Map<String, String>>> getSystemAndBusinessAndStepNameByResourceCode(@RequestBody @ApiIgnore ConfExclusiveIndicator confExclusiveIndicator) {
		return R.ok(confExclusiveIndicatorService.getSystemAndBusinessAndStepNameByResourceCode(confExclusiveIndicator));
	}

	/**
	 * 根据业务资源查询网端信息
	 * @param
	 * @return
	 */
	@GetMapping("/segmentInfo")
	@ApiOperation(value = "根据业务资源获取系统,业务名称，步骤名称信息", notes = "根据业务资源获取系统,业务名称，步骤名称信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCode", value = "资源编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isAsc", value = "排序的方向值只能是 desc 或者 asc", paramType = "body", required = true, dataType = "String"),

	})
	public R<Page<Map<String, String>>> getSegmentInfoByResourceCode(@RequestBody @ApiIgnore ConfExclusiveIndicator confExclusiveIndicator) {
		return R.ok(confExclusiveIndicatorService.getSegmentInfoByResourceCode(confExclusiveIndicator));
	}

	/**
	 *  获取服务资源和专属指标map 服务资源对应的专属指标，list为要显示的指标
	 * @param
	 * @return
	 */
	@GetMapping("/getResourcesIndicatorsShowMap")
	@ApiOperation(value = "获取服务资源和专属指标对应关系", notes = "获取服务资源和专属指标对应关系")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "needFresh", value = "是否需要刷新", paramType = "body", required = true, dataType = "boolean")
	})
	public R<Map<String, List<String>>> getResourcesIndicatorsShowMap(@RequestParam(required = false,defaultValue = "false") boolean needFresh) {
		return R.ok(exclusiveIndicatorService.getResourcesIndicatorsShowMap(needFresh));
	}

	/**
	 *  获取业务和专属指标map 业务对应的专属指标，list为要显示的指标
	 * @param
	 * @return
	 */
	@GetMapping("/getBusinessIndicatorsShowMap")
	@ApiOperation(value = "获取业务和专属指标对应关系", notes = "获取业务和专属指标对应关系")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "needFresh", value = "是否需要刷新", paramType = "body", required = true, dataType = "boolean")
	})
	public R<Map<String, List<String>>> getBusinessIndicatorsShowMap(@RequestParam(required = false,defaultValue = "false") boolean needFresh) {
		return R.ok(exclusiveIndicatorService.getResourcesIndicatorsShowMap(needFresh));
	}

	/**
	 *  获取端到端关联专属指标 业务对应的专属指标，list为要显示的指标
	 * @param
	 * @return
	 */
	@GetMapping("/querySegmentConnectList")
	@ApiOperation(value = "获取端到端关联专属指标", notes = "获取端到端关联专属指标")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "needFresh", value = "是否需要刷新", paramType = "body", required = false, dataType = "boolean")
	})
	public R<Map<String, HashMap<String, Integer>>> querySegmentConnectList( @RequestParam(required = false,defaultValue = "false") boolean needFresh) {
		return R.ok(exclusiveIndicatorService.querySegmentConnectList(needFresh));
	}


	/**
	 * 批量修改
	 * @param confExclusiveIndicator
	 * @return
	 */
	@ApiOperation(value = "批量修改", notes = "批量修改")
	@PostMapping("/batchEdit")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "id(支持多选)", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isShow", value = "是否显示: 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isDeal", value = "是否交易标示: 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isUserFlag", value = "是否交易标示: 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isChannel", value = "渠道标识: 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isRegion", value = "区域标识: 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isCustomReqCode", value = "是否是自定义返回码 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isBusinessHallCode", value = "是否是营业厅标识 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isOperatorCode", value = "是否是工号 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isPhoneNumber", value = "是否是手机号 0否, 1是 ", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isAlarm", value = "是否是告警提示 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isBackFill", value = "需要通过用户关联信息回填 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "relevanceType", value = "关联指标  0 非关联指标、 1. 是前端关联指标、2.是后端关联指标、 3. 是前后端关联指标", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isShowSensitive", value = "展示是否脱敏 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "decodeType", value = "解码方式, 0.否 1.Base64解码 2.Unicode解码 3.url解码 4.url+unicode解码", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isRetainOri", value = "是否保留原始数据 0否, 1是 ", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isFullExtraction", value = "是否全量提取 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isExportSensitive", value = "导出脱敏 0否, 1是", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "sensitiveStartValue", value = "脱敏开始数值", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "sensitiveLength", value = "脱敏长度", paramType = "body", required = true, dataTypeClass = Integer.class),
	})
	public R<String> batchEdit(@RequestBody @ApiIgnore ConfExclusiveIndicator confExclusiveIndicator){
		return exclusiveIndicatorService.batchEdit(confExclusiveIndicator);
	}


	/**
	 * 查询 可同步 的业务服务资源列表
	 * @param params 专属指标同步请求参数
	 * @return 通用返回对象
	 */
	@PostMapping("/querySureSyncResource")
	public R querySureSyncResource(@RequestBody IndicatorsSyncParams params) {
		params.setSearchType(1);
		return exclusiveIndicatorService.querySureOrAlreadySyncResource(params);
	}


	/**
	 * 导入专属指标
	 * @param file excel文件
	 * @return 通用返回对象
	 */
	@PostMapping("/import")
	public R importExcel(@RequestParam(value = "file") MultipartFile file,
							  @RequestParam(value = "resourceCode") String resourceCoding) {
		if (ObjectUtil.isEmpty(resourceCoding)) {
			return R.failed("服务资源编码不能为空");
		}
		try {
			List<String> list = Collections.singletonList(resourceCoding);
			return confExclusiveIndicatorService.importExcel(file, list);
		} catch (IOException e) {
			LOG.error(e.getMessage(), e);
		}
		return R.failed("导入失败");
	}


	/**
	 * 查询 已同步 的业务服务资源列表
	 * @param params 专属指标同步请求参数
	 * @return 通用返回对象
	 */
	@PostMapping("/queryAlreadySyncResource")
	public R queryAlreadySyncResource(@RequestBody IndicatorsSyncParams params) {
		params.setSearchType(2);
		return exclusiveIndicatorService.querySureOrAlreadySyncResource(params);
	}


	/**
	 * 专属指标同步
	 * @param params 专属指标同步请求参数
	 * @return 通用返回对象
	 */
	@PutMapping("/sync")
	public R sync(@RequestBody IndicatorsSyncParams params) {
		// 校验参数
		if (CollectionUtils.isEmpty(params.getSyncResourceCodeList())) {
			return R.failed("要同步的业务服务资源编码不能为空");
		}
		return exclusiveIndicatorService.sync(params);
	}


	/**
	 * 专属指标同步移除
	 * @param params 专属指标同步请求参数
	 * @return 通用返回对象
	 */
	@PutMapping("/unSync")
	public R unSync(@RequestBody IndicatorsSyncParams params) {
		// 校验参数
		if (CollectionUtils.isEmpty(params.getUnSyncResourceCodeList())) {
			return R.failed("要移除的业务服务资源编码不能为空");
		}
		return exclusiveIndicatorService.unSync(params);
	}


	/**
	 * 专属指标同步所有
	 * @param params 专属指标同步请求参数
	 * @return 通用返回对象
	 */
	@PutMapping("/syncAll")
	public R syncAll(@RequestBody IndicatorsSyncParams params) {
		params.setSearchType(1);
		return exclusiveIndicatorService.syncAll(params);
	}

	/**
	 * 专属指标同步移除所有
	 * @param params 专属指标同步请求参数
	 * @return 通用返回对象
	 */
	@PutMapping("/unSyncAll")
	public R unSyncAll(@RequestBody IndicatorsSyncParams params) {
		params.setSearchType(2);
		return exclusiveIndicatorService.unSyncAll(params);
	}



}
